#!/usr/bin/env python
from setup_utils import *
import shutil
import distsetup
import glob
import os
from distutils.sysconfig import get_python_lib

# ids.client

pdir = get_python_lib()
if not os.access(pdir, os.W_OK):
    abort("You are not permitted to write to the python site-packages library - try becoming root")

actions, options, arg = getActions(appDir=True)

if arg in ["CONFIGURE", "INSTALL"]:
    actions.checkNoErrors()
    
if arg == "INSTALL":

    try: 
        dir = get_python_lib()
        for f in glob.glob(dir + "/ids*egg-info") + glob.glob(dir + "/ids.py*"): 
            os.remove(f)
        distsetup.run()
        shutil.rmtree("build")
        for f in glob.glob("*.pyc"): os.remove(f)
               
        if options.verbose: print "Installed python ids.client" 

    except Exception, e:
        abort(str(e))
                
if arg == "UNINSTALL":
    
    try: 
        dir = get_python_lib()
        for f in glob.glob(dir + "/ids*egg-info") + glob.glob(dir + "/ids.py*"): 
            if options.verbose: print "Uninstalled", f
            os.remove(f)

    except Exception, e:
        abort(str(e))       
    
            
    
